version 14.2
#delimit ;
log using "F:\Government Formation in Asian-Pacific Democracies.log", replace;
set more off;

* ***************************************************************** *;
* ***************************************************************** *;
* File-Name: model4_pp_f1_3.do *;
* Date: 5/30/2022 *;
* Author: MG *;
* Purpose: Marginal effect plot (Presidential Formateur: Veto Players) *;
* Input File: data_stata_pp.dta *;
* Data Output: None *;
* Previous file: None *;
* Machine: laptop *;
* **************************************************************** *;
* **************************************************************** *;

use "F:\Government Formation in Asian-Pacific Democracies\Portfolio Allocation\data_stata_pp.dta", clear;


gen portfolioshare = . ;

replace portfolioshare = party_port2/gov_port2 ;

gen seatshare = . ;

replace seatshare = party_seats/gov_seats ;

gen parliamentary = . ;
 
replace parliamentary = 1 if presidential ==0 ;

replace parliamentary = 0 if presidential == 1 ;

gen seatshare_parl = . ;

replace seatshare_parl = seatshare * parliamentary ;

gen formateur_parl = . ;

replace formateur_parl = formateur * parliamentary ;

rename h_polcon5_vdem vetoplayers ;

gen seat_vetoplayers = . ;

replace seat_vetoplayers = seatshare * vetoplayers ;

gen vetoplayers_parl = . ;

replace vetoplayers_parl = vetoplayers * parliamentary ;

gen formateur_vetoplayers = . ;

replace formateur_vetoplayers = formateur * vetoplayers ;

gen form_vetoplayers_parl = . ;

replace form_vetoplayers_parl = formateur * vetoplayers * parliamentary ;

gen seat_vetoplayers_parl = . ;

replace seat_vetoplayers_parl = seatshare * vetoplayers * parliamentary ;

************************* ;
*  Summarize variables    ;
************************* ;

sum;


********************************************************************** ;
*  Table 1, Model 4, re-arranged to put seatshare IVs last           ;
* Y = b0 + b1X + b2W + b3Z + b4XW + b5XZ + b6WZ * b7XZW + controls + e ;
*    formateur is X, parliamentary is W, vetoplayers is Z              ;
* formateur_parl =XW, formateur_vetoplayers =XZ, vetoplayers_parl =WZ, ; 
* form_vetoplayers_parl is XWZ, then control variables                 ; 
********************************************************************** ;

regress portfolioshare formateur parliamentary vetoplayers 
formateur_parl formateur_vetoplayers vetoplayers_parl 
form_vetoplayers_parl 
seatshare seatshare_parl seat_vetoplayers seat_vetoplayers_parl, cluster(cabinetcode) ;

**************************************************************** ;
*  grab the elements of the estimated coefficient vector and     ;
*  the variance-covariance matrix                                ;
**************************************************************** ;

matrix b=e(b);
matrix V=e(V);

scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];
scalar b6=b[1,6];
scalar b7=b[1,7];

scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];
scalar varb6=V[6,6];
scalar varb7=V[7,7];
scalar covb1b5=V[1,5];

scalar list b1 b2 b3 b4 b5 b6 b7 varb1 varb2 varb3 varb4 varb5 varb6 varb7 covb1b5;

estat vce;

* **************************************************************** *;
*     Calculate data necessary for  marginal effect plot           *;
*       Create values for horizontal axis                          *;
* **************************************************************** *;

set obs 1000;

gen MVZ = (_n-1)/1000;

replace MVZ=. if _n>1000;


* **************************************************************** *;
* We want to calculate the marginal effect of X (formateur) on     *;
* Y (portfolioshare) for all values of the modifying variable Z    *;
* (legpower). We want to calculate this marginal effect when Z     *;
* changes for a specific value of the second modifying variable W  *;
* (parliamentary), when W = 0 (presidential regimes)               *;
* **************************************************************** *;

gen marginal_formateur = b1+b5*MVZ;

gen se_formateur = sqrt(varb1+varb5*(MVZ^2)+2*MVZ*covb1b5);

gen bound = 1.96*se_formateur;

gen upper = marginal_formateur+bound;

gen lower = marginal_formateur-bound;

gen yline=0;

*gen conb0=b1+b4*0+b5*MVZ+b7*(0*MVZ) if _n<100;



*     ****************************************************************  *;
*     Produce Figure 1.1(c): Effect of Formateur on Portfolioshare      *;
*     over a range of Veto Player values for presidential cases         *;
*     ****************************************************************  *;

graph twoway hist vetoplayers if parliamentary==0 & vetoplayers<1, width(0.04) percent color(gs15) yaxis(2)
    || line marginal_formateur MVZ if MVZ<1 & MVZ>0, clpattern(solid) clwidth(medthick) clcolor(black) yaxis(1)
    || line lower MVZ if MVZ<1 & MVZ>0, clpattern(dash) clwidth(thin) clcolor(red)
    || line upper MVZ if MVZ<1 & MVZ>0, clpattern(dash) clwidth(thin) clcolor(red)
    || line yline MVZ, clpattern(solid) clwidth(thin) clcolor(black)
    ||,
    xlabel(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, nogrid labsize(2.5))
    ylabel(-1.0 -0.75 -0.5 -0.25 0 0.25 0.5 0.75 1 1.25 1.5 1.75 2, axis(1) nogrid labsize(2.5))
    ylabel(0 10 20 30 40 50, axis(2) nogrid labsize(2.5) labcolor(gs12) tlcolor(gs12))
        yscale(noline alt)
        yscale(noline alt axis(2))
        xscale(noline)
        legend(off)
        title("{stSerif:(c) Veto Players and Formateur Bonus}",  size(3.5))
        xtitle("{stSerif:Veto Players}",  size(3) height(7) )
        ytitle("{stSerif:Percentage of Observations}", color(gs12) axis(2) size(3) margin(5 0 0 0))
        ytitle("{stSerif:Marginal Effect of Formateur}", size(3) height(7)) 
        scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)); 

      
graph export "F:\Government Formation in Asian-Pacific Democracies\Portfolio Allocation\model6.wmf", replace; 
 
 
 
 
log close;
exit;

